package com.coolyu.spring.dao;

import com.coolyu.spring.model.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;
import java.util.Map;

/**
 * Created by yuweimei on 2017/11/6.
 */
@Repository("jdbcUserDao")
public class UserDao implements IUserDao {

    private JdbcTemplate jdbcTemplate;


    @Resource
    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    @Override
    public void add(User user) {
        this.jdbcTemplate.update(
                "insert into t_user (username, password,nickname) values (?,?,?)",
                user.getUsername(), user.getPassword(), user.getNickname());

    }

    @Override
    public void update(User user) {
        this.jdbcTemplate.update(
                "update t_user set username = ?,password=?,nickname=?  where id = ?",
                user.getUsername(), user.getPassword(), user.getNickname(), user.getId());

    }

    @Override
    public void delete(int id) {
        this.jdbcTemplate.update("delete from t_user where id = ?", id);
    }

    @Override
    public User load(int id) {

        return null;
    }

    @Override
    public List<Map<String, Object>> list() {

        return null;
    }


}
